#ifndef _NO_ACE_COMPONENT
#pragma once
#include "ace/Asynch_Acceptor.h"
#include "ServerHandler.h"
namespace XGC
{
	namespace net
	{
		typedef ACE_Asynch_Acceptor< ace_NetworkHandle > AsyncAcceptorBase;

		class ace_AsyncAcceptor : public AsyncAcceptorBase
		{
		public:
			ace_AsyncAcceptor( create_handler_func pFunc, long_ptr lParam );
			~ace_AsyncAcceptor(void);

			/**
			* Template method to validate peer before service is opened.
			* This method is called after a new connection is accepted if the
			* @a validate_connection argument to @c open() was non-zero or
			* the @c validate_new_connection() method is called to turn this
			* feature on.  The default implementation returns 0.  Users can
			* reimplement this method to perform validation of the peer
			* using it's address, running an authentication procedure (such as
			* SSL) or anything else necessary or desireable. The return value
			* from this method determines whether or not ACE will continue
			* opening the service or abort the connection.
			*
			* @param result    Result of the connection acceptance.
			* @param remote    Peer's address.
			* @param local     Local address connection was accepted at.
			*
			* @retval  -1  ACE_Asynch_Acceptor will close the connection, and
			*              the service will not be opened.
			* @retval  0   Service opening will proceeed.
			*/
			virtual int validate_connection (const ACE_Asynch_Accept::Result& result,
				const ACE_INET_Addr &remote,
				const ACE_INET_Addr& local);

			/**
			* This is the template method used to create new handler.
			* Subclasses must overwrite this method if a new handler creation
			* strategy is required.
			*/
			virtual ace_NetworkHandle *make_handler (void)
			{
				return new ace_NetworkHandle( m_pFunc( m_lParam ) );
			}

		private:
			create_handler_func m_pFunc;
			long_ptr m_lParam;
		};
	}
}
#endif